package cn.vconinfo.database.handler;

import cn.vconinfo.database.aspect.DynamicDataSourceContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 *
 * @author vconinfo
 * @createdOn 2018/4/28
 * @description:
 */
public class DynamicDataSource extends AbstractRoutingDataSource {
    private static Logger logger = LoggerFactory.getLogger(DynamicDataSource.class);
    public DynamicDataSource(){}
    @Override
    protected Object determineCurrentLookupKey() {
        String dataSourceName =  DynamicDataSourceContextHolder.getDataSourceType();
        if (dataSourceName != null) {
            logger.info("当前数据源是：{}", dataSourceName);
        } else {
            logger.debug("当前数据源是：{}", dataSourceName);
        }

        return DynamicDataSourceContextHolder.getDataSourceType();
    }
}
